package cn.strive.eams.attachment.service.impl;

import cn.strive.eams.attachment.mapper.AttachmentMapper;
import cn.strive.eams.attachment.pojo.dto.AttachmentSaveParam;
import cn.strive.eams.attachment.pojo.entity.Attachment;
import cn.strive.eams.attachment.pojo.vo.AttachmentVO;
import cn.strive.eams.attachment.service.AttachmentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.strive.eams.attachment.pojo.dto.AttachmentQuery;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class AttachmentServiceImpl implements AttachmentService {
    @Autowired
    AttachmentMapper attachmentMapper;

    @Override
    public List<AttachmentVO> selectAttachment(AttachmentQuery attachmentQuerry) {
        log.debug("查询所有附件表信息：attachmentQuerry={}",attachmentQuerry);
        List<AttachmentVO> list = attachmentMapper.selectAttachment(attachmentQuerry);
        return list;
    }

    @Override
    public void saveAttachment(AttachmentSaveParam attachmentSaveParam) {
        log.debug("保存资产信息：attachmentSaveParam",attachmentSaveParam);
        Attachment attachment = new Attachment();
        BeanUtils.copyProperties(attachmentSaveParam,attachment);
        if (attachment.getId() == null){
            attachment.setCreateTime(new Date());
            attachmentMapper.insert(attachment);
        }else {
            attachment.setUpdateTime(new Date());
            attachmentMapper.update(attachment);
        }
    }
    @Override
    public void deleteAttachment(Long id) {
        log.debug("删除资产信息：id={}",id);
        attachmentMapper.deleteAttachment(id);
    }


}
